FROM php:8.0-fpm

# 安装系统依赖
RUN apt-get update && apt-get install -y \
    libssl-dev \
    libbrotli-dev \
    libzip-dev \
    zlib1g-dev \
    libpng-dev \
    libjpeg-dev \
    libfreetype6-dev \
    libpq-dev \
    git \
    unzip \
    curl \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

# 安装 PHP 扩展
RUN docker-php-ext-configure gd --with-freetype --with-jpeg \
    && docker-php-ext-configure zip \
    && docker-php-ext-install -j$(nproc) \
    pdo_mysql \
    mysqli \
    zip \
    gd \
    bcmath \
    pcntl \
    sockets \
    opcache

# 安装 Redis 扩展
RUN pecl install redis && docker-php-ext-enable redis

# 安装兼容 PHP 8.0 的 Swoole 扩展（5.0.3）
RUN pecl install swoole-5.0.3 && docker-php-ext-enable swoole

# 复制 php.ini 配置
COPY ./php.ini /usr/local/etc/php/php.ini

# 验证扩展是否成功安装
RUN php -m | grep -E 'pdo_mysql|zip|redis|swoole|gd|bcmath|opcache|sockets' || (echo "❌ 缺失必要扩展" && exit 1)

# 安装 Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN composer --version
